// API配置文件
const config = {
  // 开发环境
  development: {
    baseURL: 'http://localhost:8080',
    apiPath: '/api'
  },
  // 生产环境 - 优先尝试HTTPS，失败则使用HTTP
  production: {
    baseURL: 'https://www.skillith.cn',
    fallbackURL: 'http://www.skillith.cn:8080',
    apiPath: '/api'
  }
}

// 根据环境获取配置
const env = process.env.NODE_ENV || 'development'
const currentConfig = config[env]

// 导出API配置
export const API_CONFIG = {
  baseURL: currentConfig.baseURL,
  fallbackURL: currentConfig.fallbackURL,
  apiPath: currentConfig.apiPath,
  // 完整的API地址
  get fullURL() {
    return this.baseURL + this.apiPath
  },
  // 回退URL
  get fallbackFullURL() {
    return this.fallbackURL + this.apiPath
  }
}

// 导出具体的API端点
export const API_ENDPOINTS = {
  CONTACT: `${API_CONFIG.fullURL}/contact`,
  CONTACT_FALLBACK: `${API_CONFIG.fallbackFullURL}/contact`,
  ADMIN_MESSAGES: `${API_CONFIG.fullURL}/admin/messages`
}

export default API_CONFIG
